import {
  validateIP,
  validateIPSeg,
  validatePortSeg,
  validateIPAndURL,
  validateEmail,
  validatePhoneNumber,
  validateIdNumber,
  validateRegExpRule,
} from "./formValidates";

/**
 * URL 校验
 * ipv4/ipv6
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}, {validator: validateIP, trigger: string, message: string, required: boolean}]}
 */

export const domainIPSeg = [
  { required: true, message: "请输入IP段", trigger: "blur" },
  { required: true, validator: validateIPSeg, trigger: "blur" },
];

export const domainPortSeg = [
  { required: true, message: "请输入端口段", trigger: "blur" },
  { required: true, validator: validatePortSeg, trigger: "blur" },
];

/**
 * 端口 校验
 * 0~65535
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}, {min: number, max: number, trigger: string, message: string}]}
 */
export const portRule = [
  { required: true, message: "请输入端口号", trigger: "blur" },
  {
    min: 1,
    max: 65535,
    type: "number",
    message: "请输入正确的端口号,范围1~65535",
    trigger: "blur",
  },
];

/**
 * 身份证号码 验证
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}]}
 */
export const idNumberRule = [
  { required: true, message: "请输入身份证号码", trigger: "blur" },
  { required: true, validator: validateIdNumber, trigger: "blur" },
];

/**
 * 邮箱账号 验证
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}]}
 */
export const emailRule = [
  { required: true, message: "请输入邮箱地址", trigger: "blur" },
  {
    required: true,
    message: "请输入正确的邮箱账号",
    validator: validateEmail,
    trigger: "blur",
  },
];

/**
 * 手机号码 验证
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}]}
 */
export const phoneNumberRule = [
  { required: true, message: "请输入手机号码", trigger: "blur" },
  {
    required: true,
    message: "请输入正确的手机号码",
    validator: validatePhoneNumber,
    trigger: "blur",
  },
];

/**
 * 排序 验证
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}]}
 */
export const sortRule = [
  { required: true, message: "请输入排序值", trigger: "blur" },
  {
    min: 1,
    max: 99,
    type: "number",
    message: "请输入正确的排序值,范围1~99",
    trigger: "blur",
  },
];

/**
 * 正则 验证
 * @param name
 * @returns {[{trigger: string, message: string, required: boolean}]}
 */
export const regExpRule = [
  { required: true, message: "请输入匹配正则", trigger: "blur" },
  { required: true, validator: validateRegExpRule, trigger: "blur" },
];

/**
 * 特殊字符 验证
 * @type {[{trigger: string, message: string, required: boolean}]}
 */
export const specialCharRule = [
  { required: true, message: "特殊规则", trigger: "blur" },
];
